<?php
class ekstrakulikuler extends MY_Controller{
    function ekstrakulikuler(){
        parent::MY_Controller();
        $this->data['title'] = "Master Data Ekstrakulikuler";
        $this->load->model('m_ekstrakulikuler');
    }
    function index(){
        $this->data['content'] = "ekstrakulikuler/v_ekstrakulikuler";
        $this->data['listEkstrakulikuler'] = $this->m_ekstrakulikuler->getListEkstrakulikuler();
        
        $this->render($this->data);
    }
    function add_ekstrakulikuler_form(){
        $this->data['content'] = "ekstrakulikuler/v_ekstrakulikuler";
        $this->data['subLink'] = "ekstrakulikuler/add_ekstrakulikuler_proses";
        $this->data['formTitle'] = "Form Tambah Data Ekstrakulikuler";
        $this->data['formView'] = "ekstrakulikuler/addEkstrakulikulerForm";
        $this->data['listEkstrakulikuler'] = $this->m_ekstrakulikuler->getListEkstrakulikuler();
        
        $this->render($this->data);
    }
    function edit_ekstrakulikuler_form($id){
        $this->data['content'] = "ekstrakulikuler/v_ekstrakulikuler";
        $this->data['subLink'] = "ekstrakulikuler/edit_ekstrakulikuler_proses";
        $this->data['formTitle'] = "Form Edit Data Ekstrakulikuler";
        $this->data['formView'] = "ekstrakulikuler/editEkstrakulikulerForm";
        $this->data['dataInput'] = $this->m_ekstrakulikuler->getEkstrakulikulerById($id);
        $this->data['listEkstrakulikuler'] = $this->m_ekstrakulikuler->getListEkstrakulikuler();
        
        $this->render($this->data);
    }
    function add_ekstrakulikuler_proses(){
        $data = array('nama' => $this->input->post('nama'),
            'keterangan' => $this->input->post('keterangan'));
        $insert = $this->m_ekstrakulikuler->addEkstrakulikuler($data);
        if($insert == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect('ekstrakulikuler');
    }
    function edit_ekstrakulikuler_proses(){
        $data = array('id' => $this->input->post('id'),
            'nama' => $this->input->post('nama'),
            'keterangan' => $this->input->post('keterangan'));
        $update = $this->m_ekstrakulikuler->editEkstrakulikuler($data);
        if($update == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("ekstrakulikuler");
    }
    function delete_ekstrakulikuler($id){
        $delete = $this->m_ekstrakulikuler->deleteEkstrakulikuler($id);
        if($delete == TRUE){
            $this->session->set_flashdata("message",3);
        }else{
            $this->session->set_flashdata("message",4);
        }
        
        redirect('ekstrakulikuler');
    }
}
?>
